package routers

import (
	"server/app/middleware"
	"server/app/service"
	"server/core"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.Default()

	r.Use(middleware.Cors(), middleware.ErrorRecover())
	r.Static("/static", "./static")
	r.StaticFile("/favicon.ico", "./public/favicon.ico")

	r.NoMethod(func(ctx *gin.Context) {
		panic("请求方法不存在")
	})
	r.NoRoute(func(ctx *gin.Context) {
		panic("请求路由不存在")
	})

	r.GET("/", func(c *gin.Context) {
		c.Writer.WriteString("Hello, World!")
	})
	r.GET("/wss", func(c *gin.Context) {
		service.WebsocketService.HandleWebsocket(c.Writer, c.Request)
	})

	group := r.Group("/")
	core.RegisterGroup(group, LoginGroup)

	return r
}
